//
//  TimerStr.m
//  zaipin
//
//  Created by WDL on 16/10/14.
//  Copyright © 2016年 master. All rights reserved.
//

#import "TimerStr.h"

@implementation TimerStr


+ (NSNumber *)currentTimestampWithLongLongFormat
{
    double timeStamp = ceil([[NSDate date] timeIntervalSince1970] * 1000);
    
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setGeneratesDecimalNumbers:false];
    NSNumber *timeNumber = [NSNumber numberWithDouble:timeStamp];
    NSString *timeString = [formatter stringFromNumber:timeNumber];
    
    // NSTimeInterval is defined as double
    return [NSNumber numberWithLongLong:[timeString longLongValue]];
}

+(NSString *)loadCurrentTimer:(NSString *)currentData
{
    NSString*str=currentData;//时间戳
    
    NSTimeInterval time =[str doubleValue];//因为时差问题要加8小时 == 28800 sec
    
    NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSLog(@"date:%@",[detaildate description]);
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];
    
    return currentDateStr;
    
}



+(NSString *)loadCurrentChatTimer:(NSString *)currentData
{
    NSString*str=currentData;//时间戳
    
    NSTimeInterval time =[str doubleValue];//因为时差问题要加8小时 == 28800 sec
    
    NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSLog(@"date:%@",[detaildate description]);
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"MM-dd HH:mm"];
    
    NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];
    
    return currentDateStr;
    
}

+(NSString *)loadCurrentTimerBritch:(NSString *)currentData
{
    NSString*str=currentData;//时间戳
    
    NSTimeInterval time =[str doubleValue];//因为时差问题要加8小时 == 28800 sec
    
    NSDate*detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSLog(@"date:%@",[detaildate description]);
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString*currentDateStr = [dateFormatter stringFromDate:detaildate];
    
    return currentDateStr;
    
}


+ (NSString *)createdAtTimer:(NSString *)createdAt
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
//    NSDate *date = [formatter dateFromString:createdAt];
    NSDate *now = [NSDate date];
    
    NSString*str=createdAt;//时间戳
    
    NSTimeInterval time =[str doubleValue];//因为时差问题要加8小时 == 28800 sec
    
    NSDate*date=[NSDate dateWithTimeIntervalSince1970:time];

    
    // 比较微博发送时间和当前时间
    NSTimeInterval delta = [now timeIntervalSinceDate:date];
    if (delta < 60) { // 1分钟以内
        return @"刚刚";
    } else if (delta < 60 * 60) { // 60分钟以内
        return [NSString stringWithFormat:@"%.f分钟前", delta/60];
    } else if (delta < 60 * 60 * 24) { // 24小时内
        float befordelte = delta/(60*60);
        return [NSString stringWithFormat:@"%d小时前", (int)befordelte];
    } else {
        formatter.dateFormat = @"yyyy-MM-dd";
        return [formatter stringFromDate:date];
    }
}



@end
